﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IRepositories;
using GestionLinqLibData;

namespace LinqRepositories
{
   public class LinqNoteRepository : INoteRepository
    {
        private GestionDataClassesDataContext db = new GestionDataClassesDataContext();

        public IEnumerable<note> AddEntries(int id_matiere)
        {
            IEnumerable<note> notesToGenerate = new List<note>();
            foreach (var type in db.type_exam)
            {
                foreach (var eleve in db.eleve)
                {
                    (notesToGenerate as List<note>).Add(new note { id_exam = type.id_exam, id_matiere = id_matiere, num_inscription = eleve.num_inscription });
                }
            }

            db.note.InsertAllOnSubmit(notesToGenerate);
            db.SubmitChanges();
            
            return notesToGenerate;
        }
     

        public IEnumerable<note> ConsulterNote(int id_matiere, int idexam)
        {
            if(idexam !=0)
            return db.note.Where(n => n.id_matiere == id_matiere).Where(n => n.id_exam == idexam).ToList();

            return db.note.Where(n => n.id_matiere == id_matiere).ToList();
        }

        public IEnumerable<note> ConsulterNote(int id_matier)
        {
          return  ConsulterNote(id_matier, 0);
        }

        public IEnumerable<note> AddNote(IEnumerable<note> listeNote)
        {
            db.note.InsertAllOnSubmit(listeNote);
            db.SubmitChanges();

            return listeNote;
        }

        
    }
}
